﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.Skins;
using DevExpress.LookAndFeel;
using DevExpress.UserSkins;
using DevExpress.XtraEditors;
using DevExpress.XtraPivotGrid;
using csds;
using NewStation;
using View.Statistics;
using View.History;
using View.Report;
using DevExpress.XtraBars.Helpers;
using View.Table;
using View.Journal;
using System.Threading;
using TestMySqlConnetPoll;
using System.Collections;
using View.Alarm;
using View.Common;
using View.Chart.WDW;
using View.Chart.DC;
using View.Chart.ZNGD;
using ReplayDataFile;
using System.Diagnostics;
using View.Journal.UserView;
using View.Replay;
using DevExpress.XtraSplashScreen;


namespace View
{
    public partial class MainForm : XtraForm
    {
        private Thread flashRealThread; //实时值刷新线程
        private bool ThreadStop = false;
        public MainForm()
        {
            InitializeComponent();

            splashScreenManager1.ShowWaitForm();


            flashRealThread = new Thread(FlashRealData);
            flashRealThread.Start();
            //popupMenu1
            SkinHelper.InitSkinPopupMenu(popupMenu1);

            //开始设置时间
            timer_Clock.Start();
            Timer_Clock_Tick(null, null);

            timer_real.Enabled = true;

            c_ReceiveData.NewAlarmEvent += RealTimeValue_NewAlarmEvent;

            MySql.HasRepaly += MySql_HasRepaly;
            //this.dockPanel_Server.Hide();

            ReadStationCfg();
            ReadRealTimeAlarm();
            splashScreenManager1.CloseWaitForm();
        }

        void MySql_HasRepaly(object sender, EventArgs e)
        {
            if (SplashScreenManager.Default != null && SplashScreenManager.Default.IsSplashFormVisible == true)
            {
                SplashScreenManager.CloseForm();
            }

            if (Process.GetProcessesByName("ReplayView").Length > 0)
                return;

            Process pro = new Process();

            pro.StartInfo.FileName = @"E:\2013微机监测\备份20140421\DXStation2013\ReplayView\bin\x86\Debug\ReplayView.exe";
            pro.StartInfo.Arguments = string.Format("{0}", sender);

            //Console.WriteLine("进程{0}开始启动。。", i);
            pro.Start();
            if (pro != null)
            {
                pro.WaitForExit();
            }
        }

        protected override void OnClosing(CancelEventArgs e)
        {
            ThreadStop = true;
            //c_Device.StopAllThread();
            System.Diagnostics.Process.GetCurrentProcess().Kill();
            base.OnClosing(e);
        }

        private void ReadRealTimeAlarm()
        {
            rtAlarmTable tb = new rtAlarmTable();
            tb.Read();
            while (!tb.Ready_Read)
            {
                Thread.Sleep(20);
                if (tb.ErrorFlag != 0) break;
            }
            foreach (byte key in tb.ValueList.Keys)
            {
                for (int i = 0; i < tb.ValueList[key].Count; i++)
                {
                    HistroyAlarmObj t = MySql.ConvertAlarmObjToDisplay(tb.ValueList[key][i]);
                    UtilityFunc.source.Add(t);
                    
                    string k = t.AlarmLevel;
                    if (UtilityFunc.sourceLevel.ContainsKey(k))
                    {
                         UtilityFunc.sourceLevel[k].Add(t);
                    }
                    else
                    {
                        List<HistroyAlarmObj> tmp = new List<HistroyAlarmObj>();
                        tmp.Add(t);
                        UtilityFunc.sourceLevel.Add(k, tmp);
                    }
                }
            }            
            ThreadPool.QueueUserWorkItem(new WaitCallback(CheckRealTimeAlarmSum), null);
        }

        /// <summary>
        /// 刷新实时值
        /// </summary>
        private void FlashRealData()
        {
            while (!ThreadStop)
            {
                //c_RealTimeValue.RefreshRealTimeData();
                BitArray tempdigitsstatus = new BitArray(4046);
                int index = 0;
                for (int i = 0; i < c_RealTimeValue.ReceiveKGLData.Value.Count; i++)
                {
                    for (int j = 0; j < 8; j++)
                    {
                        if (index >= c_RealTimeValue.ReceiveKGLData.kglNum)
                            break;
                        tempdigitsstatus[index] = (c_RealTimeValue.ReceiveKGLData.Value[i] & (int)Math.Pow(2, j)) == (int)Math.Pow(2, j) ? true : false;
                        index++;
                    }
                }

                if (sform != null)
                    sform.changetest(tempdigitsstatus);

                Thread.Sleep(1000);
            }
        }

        private void btnServer_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            //XtraForm1 form = new XtraForm1();
            //form.MdiParent = this;
            //form.Show();
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void btnAnalysis_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            try
            {
                XtraFormReport rep = new XtraFormReport() { MdiParent = this };
                rep.Show();
            }
            catch(Exception ex) { }
        }

        /// <summary>
        /// 时间更新
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Timer_Clock_Tick(object sender, EventArgs e)
        {
            lblRealText.Caption = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
            //panel_status_write.Invalidate();
            if (C_MyPipe.SendPipeConnect)
                color_write = Color.DarkGreen;
            else
                color_write = Color.Red;

            if(C_MyPipe.ReadPipeConnect)
                color_read = Color.DarkGreen;
            else
                color_read = Color.Red;
            this.panel_status_read.Invalidate();
            this.panel_status_write.Invalidate();
            //lblPoolStatus.Appearance.ForeColor = 
        }

        int GetStringLength(string str)
        {
            int counter = 0;
            int pos = 0;
            while (pos < str.Length)
            {
                if (str[pos] != ':')
                    counter++;
                pos++;
            }
            return counter;
        }

        /// <summary>
        /// 设备状态图
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void BtnState_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            FrmState frm = new FrmState();
            frm.MdiParent = this;
            //frm.ControlBox = false;
            frm.Show();    
        }

        /// <summary>
        /// 列控状态图
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void BtnState_LK_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {

        }

        /// <summary>
        /// CTC状态图
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void BtnState_CTC_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {

        }

        /// <summary>
        /// 站场图
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void BtnStationMap_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            if (sform != null)
                sform.Activate();
            //ReadStationCfg();
            //this.bar1.Visible = false;
        }

        void ReadStationCfg()
        {
            string FileName = Application.StartupPath + "\\StartCfg.ini";
            CIniFile IniFile = new CIniFile();
            int RecSum;
            IniFile.SetFileName(FileName);//设置文件名（包括路径）
            IniFile.SetSecName("车站数目");//设置段名
            RecSum = IniFile.GetInt("个数", 0);//读子项目数目
            List<StationPara> lsp = new List<StationPara>();
            for (int i = 1; i <= RecSum; ++i)
            {
                IniFile.SetSecName("车站" + i);//设置段名
                string n = "";
                StationPara sp = new StationPara();
                IniFile.GetString("StationName", ref n, "", 30);
                sp.StationName = n;
                IniFile.GetString("StationCode", ref n, "", 30);
                sp.StationCode = n;
                IniFile.GetString("CFGPath", ref n, "", 100);
                sp.CFGPath = n;
                IniFile.GetString("DatabaseIp", ref n, "", 100);
                sp.DatabaseIp = n;
                lsp.Add(sp);

                LoadStation(sp);
              }
        }
        csds.StationForm sform = null;
        private void LoadStation(csds.StationPara para)
        {
            sform = new csds.StationForm(this, para);
            sform.CMenu_Control_Click += new MyMouseEventHandler(sform_CMenu_Control_Click);
            sform.MenuEven += sform_MenuEven;
            sform.FLBLEvent += new EventHandler(sform_FLBLEvent);
            sform.MdiParent = this;
            
            //sform.LayoutMdi(MdiLayout.TileHorizontal);
            ////sform.WindowState = FormWindowState.Maximized;
            Guid guid = Guid.NewGuid();
            sform.guid = guid;
            sform.Text = para.StationName;

            sform.KeyDown += sform_KeyDown;
            sform.Show();
        }

        void sform_MenuEven(MenuEventArgs args)
        {
            CreateSubWindowWithMenuID(args.menuID.ToString(), args.devType, args.devName);
        }

        private void FindForm(string strFrmName)
        {
            foreach (Form fm in Application.OpenForms)
            {
                if (fm.Text.Contains(strFrmName))
                {
                    fm.Close();
                    return;
                }
            }
        }

        DemoChartForm frm_real = null;         //实时曲线
        DemoChartForm frm_day = null;          //日曲线
        DemoChartForm frm_month = null;        //月曲线
        DemoChartForm frm_year = null;         //年曲线
        FrmDailyTable tTable = null;           //日报表

        /// <summary>
        /// 根据菜单创建对应窗体
        /// </summary>
        /// <param name="menu"></param>
        public void CreateSubWindowWithMenuID(string strMenuID, string strDeviceType ,string strDevName)
        {
            switch (strMenuID)
            {
                case "101":     //电源屏	    日报表
                case "201":     //UPS	        日报表
                case "301":     //外电网	    日报表
                case "401":     //站内轨道电路	日报表
                case "501":     //脉冲轨道电路  日报表
                case "601":     //电码化	    日报表
                case "701":     //区间轨道电路  日报表
                case "801":     //道岔	        日报表
                case "1001":    //电缆绝缘	    日报表
                case "1101":    //电源漏流	    日报表
                case "1201":    //防灾	        日报表
                case "1301":    //半自动闭塞	日报表
                case "1401":    //站联	        日报表
                case "1501":    //计轴	        日报表
                case "1601":    //区间监测	    日报表
                    FindForm("日报表");
                    tTable = new FrmDailyTable(strDeviceType);
                    tTable.Show(this);
                    break;
                case "102":     //电源屏	    实时曲线
                case "202":     //UPS	        实时曲线
                case "302":     //外电网        实时曲线
                case "402":     //站内轨道电路  实时曲线
                case "502":     //脉冲轨道电路  实时曲线
                case "602":     //电码化        实时曲线
                case "702":     //区间轨道电路  实时曲线
                case "802":     //道岔	        实时曲线
                case "901":     //信号机	    实时曲线
                case "1202":    //防灾	        实时曲线
                case "1302":    //半自动闭塞	实时曲线
                case "1402":    //站联	        实时曲线
                case "1502":    //计轴          实时曲线
                case "1602":    //区间监测      实时曲线
                    FindForm("实时曲线");
                    frm_real = new DemoChartForm(strDeviceType, View.Chart.ChartType_Data.Real);
                    frm_real.Show(this);
                    break;
                case "103":     //电源屏	    日曲线
                case "203":     //UPS	        日曲线
                case "303":     //外电网	    日曲线
                case "403":     //站内轨道电路	日曲线
                case "503":     //脉冲轨道电路  日曲线
                case "603":     //电码化	    日曲线
                case "703":     //区间轨道电路  日曲线
                case "902":     //信号机        日曲线
                case "803":     //道岔	        日曲线
                case "1203":    //防灾	        日曲线
                case "1303":    //半自动闭塞	日曲线
                case "1403":    //站联	        日曲线
                case "1503":    //计轴	        日曲线
                case "1603":    //区间监测	    日曲线
                    FindForm("日曲线");
                    frm_day = new DemoChartForm(strDeviceType, View.Chart.ChartType_Data.DAY);
                    frm_day.Show(this);
                    break;
                case "104":     //电源屏	    月曲线
                case "204":     //UPS	        月曲线
                case "304":     //外电网	    月曲线
                case "404":     //站内轨道电路	月曲线
                case "504":     //脉冲轨道电路  月曲线
                case "604":     //电码化	    月曲线
                case "704":     //区间轨道电路  月曲线
                case "804":     //道岔	        月曲线
                case "903":     //信号机	    月曲线
                case "1002":    //电缆绝缘	    月曲线
                case "1102":    //电源漏流   	月曲线
                case "1204":    //防灾	        月曲线
                case "1304":    //半自动闭塞	月曲线
                case "1404":    //站联	        月曲线
                case "1504":    //计轴	        月曲线
                case "1604":    //区间监测	    月曲线
                    FindForm("月曲线");
                    frm_month = new DemoChartForm(strDeviceType, View.Chart.ChartType_Data.MONTH);
                    frm_month.Show(this);
                    break;
                case "105":     //电源屏	    年曲线
                case "205":     //UPS	        年曲线
                case "305":     //外电网	    年曲线
                case "405":     //站内轨道电路	年曲线
                case "505":     //脉冲轨道电路  年曲线
                case "605":     //电码化	    年曲线
                case "705":     //区间轨道电路  年曲线
                case "805":     //道岔	        年曲线
                case "1003":    //电缆绝缘	    年曲线
                case "1103":    //电源漏流	    年曲线
                case "1205":    //防灾	        年曲线
                case "1305":    //半自动闭塞	年曲线
                case "1405":    //站联	        年曲线
                case "1505":    //计轴	        年曲线
                case "1605":    //区间监测	    年曲线
                    FindForm("年曲线");
                    frm_year = new DemoChartForm(strDeviceType, View.Chart.ChartType_Data.YEAR);
                    frm_year.Show(this);
                    break;
                case "306":     //外电网故障曲线
                    FindForm("外电网故障曲线");
                    ExternalNetworkFaultCurve wdw = new ExternalNetworkFaultCurve();
                    wdw.Show(this);
                    break;
                case "506":     //高压不对称曲线
                    FindForm("高压不对称曲线");
                    GYBDCCurve gybdc = new GYBDCCurve();
                    gybdc.Show(this);
                    break;
                case "806":     //道岔动作电流曲线
                    FindForm("道岔动作电流曲线");
                    DCDZCurve dc = new DCDZCurve(DCDZCurveTYPE.道岔动作电流曲线);
                    dc.Show(this);
                    break;
                case "807":     //道岔动作功率曲线
                    FindForm("道岔动作功率曲线");
                    DCDZCurve dc_gl = new DCDZCurve(DCDZCurveTYPE.道岔动作功率曲线);
                    dc_gl.Show(this);
                    break;
                default:
                    break;
            }
        }

        /// <summary>
        /// 站场图分路不良设置
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void sform_FLBLEvent(object sender, EventArgs e)
        {           
            FrmFLBL frm = new FrmFLBL();
            frm.Location = MousePosition;
            frm.ShowDialog();
        }

        /// <summary>
        /// 站场图控件对应右键菜单事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void sform_CMenu_Control_Click(object sender, MyMouseEventArgs e)
        {
            FrmDailyTest form = new FrmDailyTest();
            form.MdiParent = this;
            form.Show();
        }

        void sform_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Escape)
            {
                this.bar1.Visible = true;
            }
        }

        private void BtnTest_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            FrmDailyTest form = new FrmDailyTest();
            form.MdiParent = this;
            form.Show();
        }

        /// <summary>
        /// 运用统计
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void BtnStatistics_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            splashScreenManager1.ShowWaitForm();
            FormStatistics form = new FormStatistics() { MdiParent = this };
            //form.ControlBox = false;
            form.Show();
            splashScreenManager1.CloseWaitForm();
        }

        private void BtnAlarm_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            splashScreenManager1.ShowWaitForm();
            HistroyQXtraForm form = new HistroyQXtraForm();
            form.MdiParent = this;
            //form.ControlBox = false;
            form.Show();
            splashScreenManager1.CloseWaitForm();
        }

        private ProgarmRunTimeTable pTable = new ProgarmRunTimeTable();

        private void BtnReplay_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {

            ReplaySetDlg dlg = new ReplaySetDlg();
            pTable.Read_TimeList();

            while (!pTable.ReadyRead)
            {
                if (pTable.ErrorFlag != 0)
                {
                    return;
                }

                Thread.Sleep(20);
            }

           

            List<TimeSegment> listTime = new List<TimeSegment>();
            int record = 0;
            foreach (KeyValuePair<objDate, List<objRunStruct>> keyvalue in pTable.RunTimeList)
            {
                foreach (objRunStruct value in keyvalue.Value)
                {
                    TimeSegment timeSeg = new TimeSegment();
                    timeSeg.BeginTime = MySql.Time_tToDateTime(value.startTime);
                    timeSeg.EndTime = MySql.Time_tToDateTime(value.overTime);
                    listTime.Add(timeSeg);
                }
                record++;
            }

            TimeSegmentList timeList = new TimeSegmentList(listTime);

            dlg.TotalTimeList = timeList;
            dlg.Init();
            DialogResult result =  dlg.ShowDialog();

            if (result != System.Windows.Forms.DialogResult.Cancel)
            {
                if (SplashScreenManager.Default != null && SplashScreenManager.Default.IsSplashFormVisible == true)
                {
                    SplashScreenManager.CloseForm();
                }
                SplashScreenManager.ShowForm(typeof(ViewWaitForm));
                SplashScreenManager.Default.SetWaitFormCaption("回放正在启动");
                SplashScreenManager.Default.SetWaitFormDescription("请等待");
            }
        }

        private void barButtonItem4_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            //DXApplication1.MainForm frm = new DXApplication1.MainForm();
            ////frm.MdiParent = this;
            ////form.ControlBox = false;
            //frm.Show();
        }

        private void btnSwitch_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            SwitchForm form = new SwitchForm();
            form.MdiParent = this;
            //form.ControlBox = false;
            form.Show();
        }

        private void btnLog_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            JournalLogForm form = new JournalLogForm();
            //form.ControlBox = false;
            form.Show(this);
        }

        private void BtnRealAlarm_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            FrmRealAlarm frmAlarm = new FrmRealAlarm();
            frmAlarm.Show(this);
        }

        /// <summary>
        /// 报警查询
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Timer_Real_Tick(object sender, EventArgs e)
        {
            if (UtilityFunc.source.Count > 0)
            {
                txtNewAlarm.Caption = UtilityFunc.source.Count + "条新报警";
            }else
            {
                txtNewAlarm.Caption = "";
            }
        }

        void RealTimeValue_NewAlarmEvent(object sender, EventArgs e)
        {
            List<ObjAlaram> delList = sender as List<ObjAlaram>;
            foreach (ObjAlaram obj in sender as List<ObjAlaram>)
            {
                HistroyAlarmObj t = MySql.ConvertAlarmObjToDisplay(obj);
                string k = t.AlarmLevel;
                if(UtilityFunc.sourceLevel.ContainsKey(k))
                {
                    bool b = false;
                    for (int i = 0; i < UtilityFunc.sourceLevel[k].Count; i++)
                    {
                        if (UtilityFunc.sourceLevel[k][i].AlarmLevel == t.AlarmLevel && UtilityFunc.sourceLevel[k][i].u_time == t.u_time && UtilityFunc.sourceLevel[k][i].dev_type == t.dev_type)
                        {
                            if (UtilityFunc.sourceLevel[k][i].devName == t.devName && UtilityFunc.sourceLevel[k][i].AlarmType == t.AlarmType)
                            {
                                UtilityFunc.sourceLevel[k][i] = t;
                                b = true;
                                break;
                            }
                        }
                    }
                    if (b == false) UtilityFunc.sourceLevel[k].Add(t);
                }
                else
                {
                    List<HistroyAlarmObj> tmp = new List<HistroyAlarmObj>();
                    tmp.Add(t);
                    UtilityFunc.sourceLevel.Add(k, tmp);
                }
                UtilityFunc.source.Add(t);
            }
            rtAlarmTable tb = new rtAlarmTable();
            UtilityFunc.bestfit = false;
            tb.Delete(delList);
            tb.Insert(delList);
            ThreadPool.QueueUserWorkItem(new WaitCallback(CheckRealTimeAlarmSum), null);
        }

        private void CheckRealTimeAlarmSum(object o)
        {
            string[] ke = new string[UtilityFunc.sourceLevel.Keys.Count];
            UtilityFunc.sourceLevel.Keys.CopyTo(ke, 0);
            List<HistroyAlarmObj>dellist = new List<HistroyAlarmObj>();
            List<ObjAlaram> delSlist = new List<ObjAlaram>();
            for(int i = 0;i<ke.Length;i++)
            {
                string k = ke[i];
                if(UtilityFunc.sourceLevel[k].Count>1000)
                {
                    try
                    {
                        UtilityFunc.sourceLevel[k].Sort((a, b) => { return DateTime.Parse(a.u_time).CompareTo(DateTime.Parse(b.u_time)); });

                        int delNum = UtilityFunc.sourceLevel[k].Count - 1000;
                        for (int x = 0; x < delNum; x++)
                        {
                            dellist.Add(UtilityFunc.sourceLevel[k][x]);
                            delSlist.Add(UtilityFunc.sourceLevel[k][x].alarmObj);
                        }
                    }
                    catch(Exception e)
                    {
                        Console.WriteLine("删除实时报警出错" + e.ToString());
                    }
                }
            }
            try
            {
                for (int i = 0; i < ke.Length; i++)
                {
                    for (int x = 0; x < dellist.Count; x++)
                    {
                        if (dellist[x].AlarmLevel == ke[i])
                        {
                            UtilityFunc.sourceLevel[ke[i]].Remove(dellist[x]);
                        }
                    }
                }
                for (int x = 0; x < dellist.Count; x++)
                {
                    UtilityFunc.source.Remove(dellist[x]);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("删除实时报警出错" + e.ToString()); 
            }
            try
            {
                rtAlarmTable tb = new rtAlarmTable();
                tb.Delete(delSlist);    //删除实时表中的报警数据.            
            }
            catch(Exception e)
            {
                Console.WriteLine("删除实时报警出错" + e.ToString());
            }
        }

        /// <summary>
        /// 系统状态
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void BtnSysStatus_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            FrmSysStatus fm = new FrmSysStatus();
            fm.Show(this);
        }

        private Color color_read;
        private Color color_write;

        private void panel_status_write_Paint(object sender, PaintEventArgs e)
        {
            Pen p = new Pen(color_write, 3);

            System.Drawing.Drawing2D.AdjustableArrowCap lineArrow =

                new System.Drawing.Drawing2D.AdjustableArrowCap(4, 4, true);

            p.CustomEndCap = lineArrow;

            e.Graphics.DrawLine(p, new Point(0, 6), new Point(70, 6));
        }

        private void panel_status_read_Paint(object sender, PaintEventArgs e)
        {
            Pen p = new Pen(color_read, 3);

            System.Drawing.Drawing2D.AdjustableArrowCap lineArrow =

                new System.Drawing.Drawing2D.AdjustableArrowCap(4, 4, true);

            p.CustomEndCap = lineArrow;

            e.Graphics.DrawLine(p, new Point(70, 6), new Point(0, 6));
        }

        /// <summary>
        /// 用户浏览记录
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void BtnUserView_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            UserViewForm frm = new UserViewForm("设备浏览记录", UserViewLogTYPE.设备浏览记录);
            frm.Show(this);
        }
                       
        /// <summary>
        /// 系统工作日志
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnSysLog_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            JournalLogForm form = new JournalLogForm();
            form.Show(this);
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void BtnViewSB_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            UserViewForm frm = new UserViewForm("设备浏览记录", UserViewLogTYPE.设备浏览记录);
            frm.Show(this);
        }

        private void BtnViewDC_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            UserViewForm frm = new UserViewForm("道岔动作电流曲线浏览记录", UserViewLogTYPE.道岔动作电流曲线浏览记录);
            frm.Show(this);
        }

        private void btnViewAlarm_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            //UserViewForm frm = new UserViewForm("报警浏览记录", UserViewLogTYPE.报警浏览记录);
            //frm.Show(this);
        }
    }
}